package com.dgut.lab.util;

import java.util.HashMap;
import java.util.Map;

public class ResponseUtil {

    public static Object ok(){
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("code", 0);
        obj.put("msg", "成功");
        return obj;
    }


    //  绑定返回前台的响应操作结果
    //  便于有bug时校验错误
    public static Object ok(Object data){
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("code", 0);
        obj.put("msg", "成功");
        obj.put("data", data);
        return obj;
    }



    public static Object fail(int code, String msg){
        Map<String, Object> obj = new HashMap<>();
        obj.put("code", code);
        obj.put("msg", msg);
        return obj;
    }

    public static Object badArgument(){
        return fail(401, "参数不对");
    }

    public static Object updatedDataFailed() {
        return fail(505, "更新数据失败");
    }

    public static Object badArgumentValue() {
        return fail(402, "参数值不对");
    }

    public static Object unlogin() {
        return fail(501, "请登录");
    }

    public static Object updatedDateExpired() {
        return fail(504, "更新数据已经失效");
    }
}
